package com.yanqu.road.server.cmd.activity.pawnshop;

import com.yanqu.road.entity.activity.pawnshop.UserPawnshop;
import com.yanqu.road.server.pb.PawnshopPb;
import com.yanqu.road.pb.activity.PawnshopProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.pawnshop.PawnshopModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_PAWNSHOP_POLITICS_READ, desc = "设置时事已读")
public class PawnshopPoliticsReadCmd extends AbstractCommand {

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(PawnshopModule.class).setPoliticsRead();
	}

	@Override
	public void sendData(GamePlayer player) {
		PawnshopProto.PawnshopPoliticsReadRespMsg.Builder respMsg = PawnshopProto.PawnshopPoliticsReadRespMsg.newBuilder();
		respMsg.setRet(ret);
		if(0 == ret){
			UserPawnshop userPawnshop = player.getModule(PawnshopModule.class).getUserPawnshop();
			PawnshopProto.DPawnshopPolitics.Builder pMsg = PawnshopPb.parseDPawnshopPolitics(userPawnshop);
			if(null != pMsg){
				respMsg.setDPolitics(pMsg);
			}
		}
		player.sendPacket(Protocol.U_PAWNSHOP_POLITICS_READ, respMsg);
	}
}
